package function;

import model.Author;
import model.GetAuthors;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class Filter {
    public static void main(String[] args) {
        List<Author> authors = GetAuthors.getAuthors();
        authors.stream()//获取流
                //对流中的元素进行条件筛选
                .filter(new Predicate<Author>() {
                    @Override
                    public boolean test(Author author) {
                        return author.getName().length()>1;
                    }
                })//遍历打印流中每个元素姓名信息
                .forEach(new Consumer<Author>() {
                    @Override
                    public void accept(Author author) {
                        System.out.println(author.getName());
                    }
                });

        //===========================
//        for (Author index:authors) {
//            System.out.println(index.getName());
//        }
        authors.stream()
                .filter(author -> author.getName().length()>1)
                .forEach(author -> System.out.println(author.getName()));
    }
}
